<%@page import="java.io.File"%>
<%@page import="online_store.utils.Constants"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="online_store.model.dto.ProductDTO"%>
<%@page import="java.util.List"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Electronix Store</title>

<link href="<c:url value="/css/login_style.css" />" rel="stylesheet" type="text/css">
<link href="<c:url value="/css/style.css" />" rel="stylesheet" type="text/css">
<link href="<c:url value="/css/table_style.css" />" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/js/boxOver.js"></script>
</head>
<body>

	<div id="main_container">

		<%@include file="../templates/header.jsp"%>

		<div id="main_content">

			<%@include file="../templates/top.jsp"%>
			
			<%@include file="../templates/crumb_navigation.jsp"%>

			<!-- end of menu tab -->

			<%@include file="../templates/left.jsp"%>

			<!-- end of left content -->

<%
	List<ProductDTO> product_list = (List<ProductDTO>) request.getAttribute("product_list");
	String successMessage = (String) request.getAttribute("successMessage");
%>

<div class="center_content" style="width: 770px">
	
	<div id="wrapper" style="min-height: 100px">
    	<h1>Products</h1> 
    </div>

	<%
		if (successMessage != null) {
	%>
	<div class="alert-success">
		<%= successMessage%>
	</div>
	<%
		}
	%>

	<div style="text-align: center;">
		<a href="<%= request.getContextPath()%>/product/addCategory.jsp" class="myButton">Add Category</a>
		<a href="<%= request.getContextPath()%>/product/getAddProductForm" class="myButton">Add Product</a>
	</div>
	
	<div id="page-wrap">

	<%
		if(product_list.size() == 0){
	%>
		<div class="alert-info">
			No data found.
		</div>
	<%
		}else{
	%>
		<table>
			<tr>
				<th>Image</th>
				<th>Name</th>
				<th>Description</th>
				<th>Price($)</th>
				<th>Category</th>
				<th>Last Update</th>
				<th>Action</th>
			</tr>
	<%
			for(int i = 0; i < product_list.size(); i++){
	%>
			<tr>
			  <td><img src='<%= request.getContextPath() + "/product_image/" + product_list.get(i).getImage() %>'/></td>
			  <td><%= product_list.get(i).getName()%></td>
			  <td><%= product_list.get(i).getDesc()%></td>
			  <td><%= product_list.get(i).getPrice()%></td>
			  <td><%= product_list.get(i).getCategory_name()%></td>
			  <td><%= new SimpleDateFormat("yyyy-MM-dd").format(product_list.get(i).getLast_update())%></td>
			  <td>
			  	<a href='<%= request.getContextPath() + "/product/getEditProductForm?product_id=" + product_list.get(i).getProduct_id()%>'>
			  		<img src="<c:url value="/images/edit.png" />" title="Edit">
			  	</a>
			  	<a href='<%= request.getContextPath() + "/product/deleteProduct?product_id=" + product_list.get(i).getProduct_id()%>'>
			  		<img src="<c:url value="/images/delete.png" />" title="Delete">
			  	</a>
			  </td>
			</tr>
	<%
			}
	%>
		</table>
	<%		
		}
	%>
	</div>


        

	

</div>









	

			<!-- end of center content -->

			<%-- <%@include file="../templates/right.jsp"%> --%>

			<!-- end of right content -->
		</div>
		<!-- end of main content -->

		<%@include file="../templates/footer.jsp"%>

	</div>

</body>
</html>